<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: HCZ <huangchengze@etrol.com>
// +----------------------------------------------------------------------

/**
 * 上传
 * @package app/admin/api
 */
namespace app\admin\controller\api;

class Upload {
	
	/**
	 * 上传文件
	 * @return Json
	 */
	public function upload(){
		//保存文件路径
		$path = input('path');
		$path = './public/upload/'.$path;
		$file = request()->file('file');
		if(!file_exists($path)){
			mkdir ($path,0777,true);
		}
		$info = $file->move($path, true, false);
		if ($info) {
			$path = substr(str_replace("\\", '/', substr($info->getPathname(), 1)), 7) ;
			
			return json(['code'=>1,'msg'=>'上传成功','data'=>['src'=>$path]]);
		} else {
			return json(['code'=>0,'msg'=>'上传失败','data'=>'']);
		}
	}


	public function wangupload(){
		//保存文件路径
		$path = input('path');

		$path = './public/upload/'.$path;
		
		$file = request()->file('file');
		return 1;

		if(!file_exists($path)){
			mkdir ($path,0777,true);
		}
		$info = $file->move($path, true, false);
		
		if ($info) {
			$path = substr(str_replace("\\", '/', substr($info->getPathname(), 1)), 7) ;
			
			return json(['errno'=>0,'data'=>$path]);
		} else {
			return json(['errno'=>0,'msg'=>'上传失败']);
		}
	}
}
